
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0802
 * @Author : WangRuoyu 
 * @Date : 2023/9/16 14:52
 */

#include "iostream"
#include "vector"

using namespace std;

class myData {
public:
    int x;
    int value;
};

int findMaxIndex(vector<myData> &p, int x) {
    int l = 1;
    int r = p.size() - 1;
    if (p[r].x < x) {
        l = r + 1;
    } else {
        while (l < r) {
            int mid = l + r >> 1;
            if (p[mid].x >= x) r = mid;
            else l = mid + 1;
        }
    }
    return l;
}

int findMinIndex(vector<myData> &p, int x) {
    int l = 1;
    int r = p.size() - 1;
    if (p[1].x > x) {
        l = 0;
    } else {
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (p[mid].x <= x) l = mid;
            else r = mid - 1;
        }
    }
    return l;
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);

    vector<myData> p;
    p.insert(p.begin(), {0, 0});

    for (int i = 0; i < n; ++i) {
        int x, value;
        scanf("%d %d", &x, &value);
        int loc = findMaxIndex(p, x);
        if (p[loc].x == x) {
            p[loc].value += value;
        } else {
            p.insert(p.begin() + loc, {x, value});
        }
    }

    for (int i = 1; i < p.size(); ++i) {
        p[i].value += p[i - 1].value;
    }

    for (int i = 0; i < k; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        int locl = findMaxIndex(p, l);
        int locr = findMinIndex(p, r);
        printf("%d\n", p[locr].value - p[locl - 1].value);
    }

    return 0;
}